<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="utf-8">
    <title>用户列表</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" href="resources/layui/css/layui.css" media="all" />
    <link rel="stylesheet" href="resources/css/public.css" media="all" />
</head>
<body class="childrenBody">
<form class="layui-form">
    <blockquote class="layui-elem-quote quoteBox">
        <form class="layui-form">
            <div class="layui-inline">
                <div class="layui-input-inline">
                    <input type="text" class="layui-input searchVal" placeholder="请输入搜索的内容" />
                </div>
                <a class="layui-btn search_btn" data-type="reload">搜索</a>
            </div>
        </form>
    </blockquote>
    <table id="custLostList" lay-filter="custLostList"></table>
    <!--操作-->
    <script type="text/html" id="custLostListBar">
        <a class="layui-btn layui-btn-xs layui-btn-normal" lay-event="defer">暂缓流失</a>
        <a class="layui-btn layui-btn-xs layui-btn-danger" lay-event="confirmLost">确认流失</a>
    </script>
</form>
<script type="text/javascript" src="resources/layui/layui.js"></script>
<script th:inline="none">
    layui.use(['form','layer','laydate','table','laytpl'],function() {
        var form = layui.form,
            layer = parent.layer === undefined ? layui.layer : top.layer,
            $ = layui.jquery,
            laydate = layui.laydate,
            laytpl = layui.laytpl,
            table = layui.table;
        //新闻列表
        var tableIns = table.render({
            elem: '#custLostList',
            url: 'custLosts',
            cellMinWidth: 95,
            page: true,//分页
            height: "full-125",
            limit: 5,
            limits: [5, 10, 15, 20, 25],
            id: "custLostListTable",
            cols: [[
                {type: "checkbox", fixed: "left", width: 50},//复选框
                {
                    field: 'customer', title: '编号', width: 200, align: "center", templet: function (row) {
                        return row.customer.custNo;
                    }
                },
                {
                    field: 'customer', title: '客户', width: 100, align: "center", templet: function (row) {
                        return row.customer.custName;
                    }
                },
                {field: 'lostManagerName', title: '客户经理', width: 100, align: "center"},
                {field: 'lostLastOrderDate', title: '上次下单时间', width: 250, align: "center"},
                {field: 'lostLastDate', title: '确认流失时间', width: 250, align: "center"},
                {field: 'lostStatus', title: '状态', width: 100, align: "center", templet: function (row) {
                        switch (row.lostStatus) {
                            case 1:
                                return "正常状态";
                            case 2:
                                return "暂缓流失";
                            case 3:
                                return "确认流失";
                        }
                    }
                },
                {title: '操作',templet: '#custLostListBar', fixed: "right", align: "center"}
            ]]
        });

        $(".search_btn").on("click",function(){
            table.reload("custLostListTable",{
                page: {
                    curr: 1 //重新从第 1 页开始
                },
                where: {
                    lostReson:$(".searchVal").val()
                }
            })
        });
        //选择
        table.on("tool(custLostList)",function (obj) {
            //获取当前行的数据
            var data=obj.data;
            switch (obj.event){
                case 'defer'://暂缓流失
                    deferCustomer(data);
                    break;
                case 'confirmLost'://确认流失
                    confirmLostCust(data);
                    break;
            }
        });
        //暂缓流失的界面
        function deferCustomer(data) {
            if(data.lostStatus!=2){
                var index=layui.layer.open({
                    title:"暂缓流失",
                    type:2,
                    content:"todeferCustomer.do",
                    success:function (layero,index) {
                        var body = layui.layer.getChildFrame('body', index);
                        body.contents().find(".lostNo").val(data.lostNo);
                        body.contents().find(".custName").val(data.customer.custName);
                        body.contents().find(".lostManagerName").val(data.lostManagerName);
                        body.contents().find(".lostLastOrderDate").val(data.lostLastOrderDate);
                        body.contents().find(".lostDelay1").val(data.lostDelay);
                        body.contents().find(".lostCustNo").val(data.customer.custNo);
                        if(data.lostStatus==1){
                            body.contents().find("input[type='radio']").eq(0).attr("checked",true);
                        }else if(data.lostStatus==2){
                            body.contents().find("input[type='radio']").eq(1).attr("checked",true);
                        }else if(data.lostStatus==3){
                            body.contents().find("input[type='radio']").eq(2).attr("checked",true);
                        }
                    }
                })
            }else{
                layer.msg("已经是暂缓状态了，你还想啥呢！");
            }

            layui.layer.full(index);//全屏显示
        }
        //确认流失页面
        function confirmLostCust(data) {
            if(data.lostStatus!=3) {
                var index = layui.layer.open({
                    title: "确认流失",
                    type: 2,
                    content: "toconfireLostCustomer.do",
                    success: function (layero, index) {
                        var body = layui.layer.getChildFrame('body', index);
                        body.contents().find(".lostNo").val(data.lostNo);
                        body.contents().find(".custName").val(data.customer.custName);
                        body.contents().find(".lostManagerName").val(data.lostManagerName);
                        body.contents().find(".lostLastOrderDate").val(data.lostLastOrderDate);
                        body.contents().find(".lostDelay1").val(data.lostDelay);
                        body.contents().find(".lostReson").val(data.lostReson);
                        body.contents().find(".lostCustNo").val(data.customer.custNo);
                        if (data.lostStatus == 1) {
                            body.contents().find("input[type='radio']").eq(0).attr("checked", true);
                        } else if (data.lostStatus == 2) {
                            body.contents().find("input[type='radio']").eq(1).attr("checked", true);
                        } else if (data.lostStatus == 3) {
                            body.contents().find("input[type='radio']").eq(2).attr("checked", true);
                        }
                    }
                })
            }else {
                layer.msg("流失状态了哦亲！")
            }
            layui.layer.full(index);//全屏显示
        }

    })
</script>
</body>
</html>